#include <bits/stdc++.h>
using namespace std;
map<string,long long> m;
long long a[6];
long long weishu[6];
int err(string s){
	for(int i=1;i<=5;i++) {
		a[i]=0;
		weishu[i]=0;
	}
	int point=0,dot=0;
	int k=1;
	for(long long i=0;i<s.size();i++){
		if(s[i]=='0' && (s[i-1]>'9' && s[i-1]<'0')) return false;
		else if(s[i]>='0' && s[i]<='9'){
			a[k]*=10;
			a[k]+=s[i]-'0';
			weishu[k]++;
		}
		else if(s[i]=='.' || s[i]==':'){
			k++;
		}
	}
	if(k!=5) return false;
	for(int i=1;i<=k-1;i++){
		if(a[i]>255 || a[i]<0) return false;
	}
	if(a[k]>65535 || a[k]<0) return false;
	int h=0;
	for(int i=1;i<=k-2;i++){
		h+=weishu[i];
		if(s[h]!='.') return false;
		else h++;
	}
	h+=weishu[k-1];
	if(s[h]!=':') return false;
	return true;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	long long n;
	cin>>n;
	string s,s1;
	for(int i=1;i<=n;i++){
		cin>>s>>s1;
		if(s[0]=='S'){
			if(!m[s1] && err(s1)!=0){
				m[s1]=i;
				cout<<"OK"<<endl;
			}
			else if(err(s1)==0) cout<<"ERR"<<endl;
			else cout<<"FAIL"<<endl;
		}
		else {
			if(m[s1]!=0 && err(s1)!=0) cout<<m[s1]<<endl;
			else if(err(s1)==0) cout<<"ERR"<<endl;
			else cout<<"FAIL"<<endl;
		}
	}
	return 0;
}
